package com.allwees.core.common.constant;

import com.baomidou.mybatisplus.core.enums.IEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
public enum EPlatform implements IEnum<String> {
	IOS("i") {
		@Override
		public boolean isApp() {
			return true;
		}
	},

	ANDROID("a") {
		@Override
		public boolean isApp() {
			return true;
		}
	},

	PC("p"),
	H5("h"),
	UNKNOWN("u"),

	TESTCASE("t") {
		@Override
		public boolean isMock() {
			return true;
		}
	};

	public boolean isApp() {
		return false;
	}

	public boolean isMock() {
		return false;
	}

	@Override
	public String getValue() {
		return name();
	}

	public static EPlatform parseFrom(String xPlatform) {
		if(StringUtils.isBlank(xPlatform)) {
			return UNKNOWN;
		}
		if("PC".equalsIgnoreCase(xPlatform)) {
			return PC;
		} else if("H5".equalsIgnoreCase(xPlatform)) {
			return H5;
		} else if(StringUtils.containsIgnoreCase(xPlatform, "ANDROID")) {
			return ANDROID;
		} else if(StringUtils.containsIgnoreCase(xPlatform, "IOS") || StringUtils.containsIgnoreCase(xPlatform, "iPhone") || StringUtils.containsIgnoreCase(xPlatform, "iPad")) {
			return IOS;
		}
		return UNKNOWN;
	}

	public static boolean isApp(String platform){
		return EPlatform.IOS.name().equalsIgnoreCase(platform)
				|| EPlatform.ANDROID.name().equalsIgnoreCase(platform);
	}

	EPlatform(String shortName) {
		this.shortName = shortName;
	}

	private final String shortName;
}
